<% layout('/layouts/default.html', {title: '客户查询', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('客户详情')}
                <% if (hasPermi('base:customer:customer:edit')){ %>
                    <button type="button" class="btn btn-primary" id="editView">${text('编辑单据')}</button>
                <% } %>
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${customer}" action="${ctx}/base/customer/customer/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<!--<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('本级排序号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="treeSort" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>-->
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:hidden path="isNewRecord"/>
							<#form:input path="customerId" id="customerId" maxlength="64" readonly="true" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerName" maxlength="200" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4">${text('上级客户')}：</label>
                            <div class="col-sm-8">
                                <#form:treeselect id="parent" title="${text('上级客户')}"
                                path="parent.customerId" labelPath="parent.customerName"
                                url="${ctx}/base/customer/customer/treeData?excludeCode=${customer.id}"
                                class="" allowClear="true" canSelectRoot="true" canSelectParent="true" readonly="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('客户名称缩写')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="customerNameAbbreviation" maxlength="200" class="form-control required" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('档案状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status" dictType="sys_search_status" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('默认担保人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="guarantorId" items="${listGuar}"
                                itemLabel="guarantorName" itemValue="guarantorId" blankOption="true" disabled="true"
                                class="form-control required" />
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('客户经理')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="accountManager" items="${listUser}"
                                itemLabel="userName" itemValue="userCode" blankOption="true" disabled="true" class="form-control required" />
                            </div>
                        </div>
                    </div>
				</div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-unit">${text('法人、经办人信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('法人姓名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="corporateName" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('法人身份证')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="corporateIdcard" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('经办人姓名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="transactorName" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('经办人身份证')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="transactorIdcard" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('地址信息')}</div>
				<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('国家/省份/城市')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:treeselect id="area" title="${text('选择')}"
                                path="area.areaCode" labelPath="area.areaName" labelValue="${customer.area.treeNames!}"
                                url="${ctx}/sys/area/treeData" returnFullName="true"
                                class="" allowClear="true"  readonly="true"/>
                            </div>
                        </div>
                    </div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('详细地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="address" maxlength="200" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('工商、账户信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('纳税人识别号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="taxpayerIdentificationNumber" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('户名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="accountName" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('账号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="accountNumber" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('银行名称及地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="bankNameAddress" maxlength="200" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('展厅信息')}</div>
                <div class="ml10 mr10">
                    <table id="customerShowroomDataGrid"></table>
                </div>
                <div class="form-unit">${text('联系人列表')}</div>
				<div class="ml10 mr10">
					<table id="customerContactDataGrid"></table>
				</div>
                <div class="form-unit">${text('准入资料明细以及附件')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('资料更新日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="dataUpdateDate" readonly="true" maxlength="20" class="form-control required" disabled="true"
                                dataFormat="date" data-type="date" data-format="yyyy-MM-dd HH:mm"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('更新周期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateCycle" class="form-control required number" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
				<div class="ml10 mr10">
					<table id="customerDataDataGrid"></table>
				</div>
                <div class="form-unit">${text('系统信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createDate" class="form-control" disabled="true"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <!--<#form:input path="createBy" class="form-control" disabled="true"/>-->
                                <#form:select path="createBy" items="${listUser}" disabled="true"
                                itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <!--<#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>-->
                                <#form:select path="updateBy" items="${listUser}" disabled="true"
                                itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化展厅DataGrid对象
$("#customerShowroomDataGrid").dataGrid({
	data: ${toJson(customer.customerShowroomList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:false, hidden:true},
		{header:'主键', name:'showroomId', editable:false, hidden:true},
		{header:'${text("展厅名称")}', name:'showroomName', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
        {header:'${text("展厅类型")}', name:'showroomType', index:'a.showroom_type', width:100, align:"center",editable:false,
            formatter: function(val, obj, row, act){
                return js.getDictLabel(${@DictUtils.getDictListJson('warehouse_xingzhi')}, val, ' ', true);
        }},
        {header:'${text("面积")}', name:'acreage', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("备注")}', name:'remarks', width:150, editable:false, edittype:'textarea', editoptions:{'maxlength':'500', 'class':'form-control', 'rows':'1'}},
		{header:'${text("客户ID")}', name:'customerId.customerId', editable:false, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#customerShowroomDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {showroomId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'customerShowroomList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,showroomId,showroomName,showroomType,acreage,remarks,customerId.customerId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
//初始化联系人DataGrid对象
$("#customerContactDataGrid").dataGrid({
	data: ${toJson(customer.customerContactList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:false, hidden:true},
		{header:'主键', name:'contactId', editable:false, hidden:true},
		{header:'${text("姓名")}', name:'contactName', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("职务")}', name:'position', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("联系电话")}', name:'phone', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("邮箱")}', name:'email', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("联系人地址")}', name:'contactPersonAddr', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
        {header:'${text("是否主要联系人")}', name:'mainFlag', index:'a.main_flag', width:100, align:"center",
            formatter: function(val, obj, row, act){
                return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, ' ', true);
        }},
		{header:'${text("客户ID")}', name:'customerId.customerId', editable:false, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#customerContactDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {contactId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'customerContactList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,contactId,contactName,position,phone,email,contactPersonAddr,mainFlag,customerId.customerId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
//初始化客户资料DataGrid对象
$("#customerDataDataGrid").dataGrid({
	data: ${toJson(customer.customerDataList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	/*columnModel: [
		{header:'状态', name:'status', editable:false, hidden:true},
		{header:'主键', name:'dataId', editable:false, hidden:true},
		{header:'${text("名称")}', name:'dataName', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
        {header:'${text("是否必填")}', name:'required', index:'a.required', width:100, align:"center", editable:false,
            formatter: function(val, obj, row, act){
                return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, ' ', true);
        }},
        {header:'${text("文件上传")}', name:'id', align:"center", width:200,
            editable: true, edittype: "custom", editoptions: {
                custom_element: function(val, editOptions) {
                    return js.template('fileuploadTpl', {
                        id: 'fileupload_'+editOptions.id, title: '区域选择',
                        bizKey: val, bizType: 'customerData_file', cssClass: ''
                    });
                }
            }
        },
        {header:'${text("客户ID")}', name:'customerId.customerId', editable:false, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],*/
    columnModel: [
        {header:'状态', name:'status', editable:false, hidden:true},
        {header:'主键', name:'dataId', editable:false, hidden:true},
        {header:'${text("客户ID")}', name:'customerId.customerId', editable:false, hidden:true},
        {header:'${text("名称")}', name:'customerDataconfig.dataconName', width:80, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
        {header:'${text("是否必填")}', name:'required', index:'a.required', width:40, align:"center",
             formatter: function(val, obj, row, act){
                 return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, ' ', true);
         }},
        /*{header:'${text("是否必填")}', name:'required', width:100,
            editable:false, edittype:'select', editoptions:{'class':'form-control',
                items: $.merge([], ${@DictUtils.getDictListJson('sys_yes_no')}),
                itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
                    $(element).select2().on("change",function(){$(this).resetValid()});
                }
            }
        },*/

        {header:'${text("文件上传")}', name:'id', align:"center", width:200,
            editable: true, edittype: "custom", editoptions: {
                custom_element: function(val, editOptions) {
                    return js.template('fileuploadTpl', {
                        id: 'fileupload_'+editOptions.id, title: '区域选择',
                        bizKey: val, bizType: 'customerData_file', cssClass: ''
                    });
                }
            }
        }
    ],
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#customerDataDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {dataId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'customerDataList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,dataId,dataName,required,customerId.customerId,customerData_file,customerData_file__del', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.$('#dataGrid').dataGrid('refreshTreeChildren',
							$('#parentCode').val(), '${customer.id}');
				});
			}
		}, "json");
    }
});

// 选择上级节点回调方法
function treeselectCallback(id, act, index, layero){
	if (id == 'parent' && (act == 'ok' || act == 'clear')){
		// 创建并初始化下一个节点信息，如：排序号、默认值
		$.get('${ctx}/base/customer/customer/createNextNode?parentCode='
				+$('#parentCode').val(), function(data){
			$('#treeSort').val(data.treeSort);
		});
	}
}
</script>

<script id="fileuploadTpl" type="text/template">//<!--<div>
<#form:fileupload id="{{d.id}}" bizKey="{{d.bizKey}}" bizType="{{d.bizType}}"
	uploadType="all" class="{{d.cssClass}}" isMini="true" preview="true"/>
</div>//--></script>

<script>
    $("#editView").click(function () {
        var id = $("#customerId").val();
        var URL = '${ctx}/base/customer/customer/form?customerId=' + id;
        window.location.href =URL;
    });
</script>




